//引入vue
import Vue from 'vue'
import Vuex from 'vuex'
import '@/plugins/axios'

//注册vue
Vue.use(Vuex)

//状态
const state = {
    row: { "index": 0 },
    show: { "status": false },
    userinfo: JSON.parse(localStorage.getItem('userinfo')),
    //首页信息
    systemhome: {
    },
    deviceinfo: [{
        "id": "1",
        "name": "Aello",
        "serial": "AK1231",
        "longitude": "45.000",
        "latitude": "67.000",
        "plugm": "Aasd",
        "status": "1",
        "time": "19981202",
        "media": "1",
        "type": "1",
        "note": "这是关于设备信息的一些注释"
    },
    {
        "id": "3",
        "name": "Aello",
        "serial": "AK1231",
        "longitude": "45.0010",
        "latitude": "67.0002",
        "plugm": "Aasd",
        "status": "1",
        "time": "19981202",
        "media": "2",
        "type": "2",
        "note": "这是关于设备信息的一些注释"
    },
    {
        "id": "2",
        "name": "admin",
        "serial": "FK1231",
        "longitude": "45.0500",
        "latitude": "67.0060",
        "plugm": "asd",
        "status": "0",
        "time": "19991202",
        "media": "3",
        "type": "3",
        "note": "这是关于设备信息的一些注释"
    },],

    //任务管理参数配置的数据信息

    //任务管理所需信息
    taskman: [
        {
            "id": "1",
            "name": "name",
            "lib_id": "1",
            "lib_name": "libname",
            "func_no": "1",
            "func_name": "funcname",
            "dev_id": "devid",
            "dev_name": "devidname",
            "note": "note",
            "period": "period",
            "usable": "1",
            "module": "module",
            "target": "target",
            "dllalg_in": [
                {
                    "data_id": "001",
                    "data_name": "dsadsa",
                    "class_name": "dwewew",
                    "repeat": "0",

                },
                {
                    "data_id": "002",
                    "data_name": "dsadsdsa",
                    "class_name": "dweswew",
                    "repeat": "1",
                },
                {
                    "data_id": "003",
                    "data_name": "dsadsdaa",
                    "class_name": "dweewew",
                    "repeat": "0",
                }
            ],
            "dllalg_out": [
                {
                    "data_id": "001",
                    "data_name": "dsadsa",
                    "class_name": "dwewew",
                    "alarm_id": "0",

                },
                {
                    "data_id": "002",
                    "data_name": "dsadsdsa",
                    "class_name": "dweswew",
                    "alarm_id": "1",

                },
                {
                    "data_id": "003",
                    "data_name": "dsadsdaa",
                    "class_name": "dweewew",
                    "alarm_id": "2",
                }
            ]

        },
        {
            "id": "2",
            "name": "name",
            "lib_id": "1",
            "lib_name": "libname",
            "func_no": "0",
            "func_name": "funcname",
            "dev_id": "devid",
            "dev_name": "devidname",
            "note": "note",
            "period": "period",
            "usable": "1",
            "module": "module",
            "target": "target",
            "dllalg_in": [
                {
                    "data_id": "001",
                    "data_name": "dsadsa",
                    "class_name": "dwewew",
                    "repeat": "0",

                },
                {
                    "data_id": "002",
                    "data_name": "dsadsdsa",
                    "class_name": "dweswew",
                    "repeat": "1",
                }
            ],
            "dllalg_out": [
                {
                    "data_id": "001",
                    "data_name": "dsadsa",
                    "class_name": "dwewew",
                    "alarm_id": "0",

                },
                {
                    "data_id": "002",
                    "data_name": "dsadsdsa",
                    "class_name": "dweswew",
                    "alarm_id": "1",

                },
                {
                    "data_id": "003",
                    "data_name": "dsadsdaa",
                    "class_name": "dweewew",
                    "alarm_id": "2",
                }
            ]

        }
    ],
    data_info: [
        {
            "id": "1",
            "name": "dsada",
            "class_name": "dsadsa",
            "alarm_id":"1"
        },
        {
            "id": "2",
            "name": "dsada",
            "class_name": "dsadsa",
            "alarm_id":"2"
        },
        {
            "id": "3",
            "name": "dsada",
            "class_name": "dsadsa",
            "alarm_id":"3"
        }
    ],
    //报警信息数据
    alarm_info: [
        {
            "id": "1",
            "time": "20190507",
            "dev_name": "FK#3",
            "file": "adsdsa.md",
            "note": "严重",
            "mean": "缺光照",
        }
    ],


    //智能库信息
    dllalg: [
        {
            "lib_id": "1",
            "name": "DA",
            "version": "版本",
            "url": "库地址",
            "uptime": "上传时间",
            "note": "说明",
            "usable": "可用性"
        },
        {
            "lib_id": "2",
            "name": "DB",
            "version": "版本",
            "url": "库地址",
            "uptime": "上传时间",
            "note": "说明",
            "usable": "可用性"
        }
    ],
    Userinfo: [{
        "id": "1",
        "name": "chen",
        "pass": "123456",
        "type": "0",
        "status": "1",
        "time_in": "19991203",
        "time_out": "19991202",
    },],

    //设备信息
    systeminfo: {
        "type": "widows",
        "version": "3.5",
        "uptime": "4.19",
        "total_ram": "8.0",
        "free_ram": "666",
        "cpu_use": "0.59",
        "cpu_type": "1024",
        "freq": "4GHZ",
        "buffer_ram": "5120",
        "serial": "46546",
        "ip": "465465.454.00",
        "mask": "255.4785536.5",
        "network": "4654",
        "dns": "9.9.9.9",
    },

    //接口类型
    media_info: [
        {
            "type": "1",
            "name": "media"
        },
        {
            "type": "2",
            "name": "medi2a"
        },
        {
            "type": "3",
            "name": "media2"
        }

    ],

    //设备状态
    options: [{
        id: "0",
        label: '在线'
    }, {
        id: "1",
        label: '离线'
    }, {
        id: "2",
        label: '禁用'
    },],

    //功能类型
    func_info: [
        {
            "type": "1",
            "name": "缺水"
        },
        {
            "type": "2",
            "name": "温度"
        },
        {
            "type": "3",
            "name": "空气"
        }

    ],
    //设备类型
    type_info: [
        {
            "type": "1",
            "name": "type001"
        },
        {
            "type": "2",
            "name": "type002"
        },
        {
            "type": "3",
            "name": "type003"
        }

    ],
    inf: [
        {
            "type": "001",
            "name": "采集器1",
            "空气温度": '30℃',
            "空气湿度": '10°',
            "土壤温度": '20℃',
            "室内温度": '20℃',
            "室内湿度": '13°',
            "采集次数": '6次',
            "最近采集时间": '2019.5.2'
        },
        {
            "type": "002",
            "name": "采集器2",
            "大气温度": '20℃',
            "大气湿度": '8°',
            "室内温度": '20℃',
            "室内湿度": '13°',
            "采集次数": '6次',
            "最近采集时间": '2019.5.2'
        },
        {
            "type": "003",
            "name": "采集器3",
            "设备温度": '20℃',
            "设备湿度": '13°',
            "采集次数": '9次',
            "最近采集时间": '2019.5.2'
        }, {
            "type": "003",
            "name": "采集器4",
            "地表温度": '30℃',
            "地表湿度": '10°',
            "地心温度": '20℃',
            "地心湿度": '13°',
            "采集次数": '5次',
            "最近采集时间": '2019.5.2'
        }

    ]
}
console.log(state.deviceinfo)
//mutations 主要用来操作state
const mutations = {
    //保存用户数据
    SAVE_USERINFO(state, userinfo) {
        localStorage.setItem('userinfo', JSON.stringify(userinfo))
        state.userinfo = userinfo
    },
    //获取设备状态信息
    GET_DEVICEINFO(state, deviceinfo) {
        state.deviceinfo = deviceinfo
    },

    //获取用户信息
    GET_USERINFO(state, userinfo) {
        console.log(1)
        state.Userinfo = userinfo
        console.log(state.Userinfo)
    },

    //获取报警信息
    GET_ALARMINFO(state, alarminfo) {
        console.log(1)
        state.alarm_info = alarminfo
        console.log(state.alarm_info)
    },


    //获取设备信息
    GET_SYSTEMINFO(state, systeminfo) {
        state.systeminfo = systeminfo
    },

    //获取首页信息
    GET_SYSTEMHOME(state, systemhome) {
        console.log("获取首页信息")
        state.systemhome = systemhome
        console.log(state.systemhome)
    },
    //获取智能库信息
    GET_DLLALG(state, dllalg) {
        console.log("获取首页信息")
        state.dllalg = dllalg
        console.log(state.dllalg)
    },
    //获取接口类型
    GET_MEDIAINFO(state, media_info) {
        console.log("获取首页信息")
        state.media_info = media_info
        console.log(state.media_info)
    },

    //获取所有数据类型
    GET_DATAINFO(state, data_info) {
        console.log("获取所有智能库类型")
        state.data_info = data_info
        console.log(state.data_info)
    },
      //获取所有智能库类型
      GET_LIBINFO(state, lib_info) {
        console.log("获取所有智能库类型")
        state.lib_info = lib_info
        console.log(state.lib_info)
    },
    //获取功能类型
    GET_FUNC(state, type_info) {
        console.log("获取所有功能类型")
        state.func_info = type_info
        console.log(state.func_info)
    },


    //獲取任務管理信息
    GET_TASKINFO(state, task_info) {
        console.log("获取首页信息")
        state.taskman = task_info
        console.log(state.taskman)
    },
    //获取设备类型
    GET_TYPEINFO(state, type_info) {
        console.log("获取首页信息")
        state.type_info = type_info
        console.log(state.type_info)
    },
    //采集信息
    GET_INF(state, inf) {
        console.log("获取采集器信息")
        state.inf = inf
        console.log(state.inf)
    },

}

//定义actions
const actions = {
    //获取设备信息
    GET_DEVICEINFO({ commit }) {
        axios.get('./action/device_status').then(res => {
            commit('GET_DEVICEINFO', res.data.device_info)
        })
    },
    //采集信息
    GET_INF({ commit }) {
        axios.get('./action/device_status').then(res => {
            commit('GET_INF', res.data.inf)
        })
    },
    //获取用户信息
    GET_USERINFO({ commit }) {
        axios.get('./action/user_status').then(res => {
            commit('GET_USERINFO', res.data.user_info)
        })
    },

    //获取报警信息
    GET_ALARMINFO({ commit }) {
        axios.get('./action/alarm_status').then(res => {
            commit('GET_ALARMINFO', res.data.alarm_info)
        })
    },

    //獲取任務管理信息
    GET_TASKINFO({ commit }) {
        axios.get('./action/task_status').then(res => {
            commit('GET_TASKINFO', res.data.task_info)
        })
    },

    //获取系统参数
    GET_SYSTEMINFO({ commit }) {
        axios.get('./action/system_arg').then(res => {
            commit('GET_SYSTEMINFO', res.data)
        })
    },

    //获取首页信息
    GET_SYSTEMHOME({ commit }) {
        axios.get('./action/system_info').then(res => {
            console.log("获取设备信息", res.data)
            console.log("获取设备信息", res.data)
            commit('GET_SYSTEMHOME', res.data)
        })
    },

    //获取接口类型
    GET_MTSTATUS({ commit }) {
        axios.get('./action/MT_status').then(res => {

            commit('GET_TYPEINFO', res.data.type_info)
            commit('GET_MEDIAINFO', res.data.media_info)
        })
    },

    //获取所有数据类型
    GET_DATAINFO({ commit }) {
        axios.get('./action/data_status').then(res => {

            commit('GET_DATAINFO', res.data.data_info)
        })
    },


    //获取所有功能类型
    GET_FUNC({ commit }) {
        axios.get('./action/func_status').then(res => {

            commit('GET_FUNC', res.data.type_info)
        })
    },
     //获取所有智能库类型
     GET_LIBINFO({ commit }) {
        axios.get('./action/lib_status').then(res => {

            commit('GET_LIBINFO', res.data.lib_info)
        })
    },

}



//创建仓库
export default new Vuex.Store({
    state,
    mutations,
    actions
})